 /**
 * DISCLIMER: 
 * this library is an opensource, feel free to edit or redistribute it
 * but use it with you own risk
 * 
 * ktutnik
 */
package org.ticlib.task
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	
	[Exclude(name="activate", kind="event")]
	[Exclude(name="deactivate", kind="event")]
	
	[Event(name="complete", type="flash.events.Event")]
	[Event(name="fault", type="mx.rpc.events.FaultEvent")]
	[Event(name="cancel", type="flash.events.Event")]
	[Event(name="connect", type="flash.events.Event")]
	public class Task extends EventDispatcher
	{
		[Bindable] public var enable:Boolean;
		[Bindable] public var resultObject:Object;
		[Bindable] public var faultObject:Object;
		[Bindable] public var isComplete:Boolean;
		[Bindable] public var isCanceled:Boolean;
		[Bindable] public var chain:Task;
		[Bindable] public var parent:Task;
		
		public function Task()
		{
		}
		
		private function initialize():void
		{
			resultObject = null;
			isComplete = false;
			isCanceled = false;
			faultObject = false;
			dispatchEvent(new Event(Event.CONNECT));
		}
		
		public function getRootParent():Task
		{
			return parent ? parent.getRootParent() : this;
		}
		
		public function isRoot():Boolean
		{
			return (getRootParent() == this)
		}
		
		public function execute():void
		{
			initialize();
		}
		
		public function stop():void
		{
			
		}
	}
}